package com.fau.wmbj.server.controller.current;

import com.fau.wmbj.server.config.CurrentUser;
import com.fau.wmbj.server.entity.User;
import com.fau.wmbj.server.flowable.domain.bo.StartProcessBo;
import com.fau.wmbj.server.flowable.service.ActTaskService;
import com.fau.wmbj.server.idempotent.annotation.RepeatSubmit;
import com.fau.wmbj.server.service.UserService;
import com.fau.wmbj.server.utils.Message;
import com.fau.wmbj.server.vo.StartTaskVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * TODO
 *
 * @author jiawei
 * @version 1.0
 * @datetime 2024/7/11 下午5:02
 */
@Slf4j
@RestController
@RequestMapping("/task")
public class TaskController {

    @Resource
    private UserService userService;
    @Resource
    private ActTaskService actTaskService;

    @RepeatSubmit(interval = 1000)
    @RequestMapping("/start-task")
    @ResponseBody
    public Message startTask(@RequestBody StartTaskVo startTaskVo, @CurrentUser User current) {
        log.info("startTask:{}", startTaskVo.toString());
        StartProcessBo startProcessBo = new StartProcessBo();
        startProcessBo.setProcessKey(startTaskVo.getProcessDefinitionId());
        startProcessBo.setBusinessKey(startTaskVo.getOrderId() + "");
        startProcessBo.setVariables(startTaskVo.getFormData());
        startProcessBo.setAuthenticatedUserId(current.getId() + "");
        Map<String, Object> map = actTaskService.startWorkFlow(startProcessBo);
        return Message.success();
    }


}
